package test.wk.job.heartbeat.slave;

import com.wk.job.Job;
import com.wk.job.heartbeat.slave.JobStateHeartbeatSource;
import com.wk.net.heartbeat.source.senders.TcpSender;



public class DemoJobStateHeartbeatSource {

	public static void main(String[] args) {
		final String TARGET_IP = "10.103.247.82";
		final int TARGET_PORT = 8086;
		final long SEND_PERIOD = 3;// 发送周期（单位：秒）

		final int UPDATE_PROGRESS_PERIOD = 2;// 更新工作状态的周期（单位：秒）

		Job observedJob = new Job("job", "北京市", 57, "2017-4-6");

		JobStateHeartbeatSource source = new JobStateHeartbeatSource(observedJob, new TcpSender(TARGET_IP, TARGET_PORT),
				SEND_PERIOD);
		source.start();

		/* 模拟Job更新进度 */
		while (true) {
			try {
				Thread.sleep(UPDATE_PROGRESS_PERIOD * 1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			
			observedJob.setJobInfo(observedJob.getJobInfo() + 1);
			if(observedJob.getJobInfo() >100){
				source.observe(null);
			}
		}
	}

}
